import { getData, postData } from './tool.js'
import { config } from './config.js'

const getPage = (data) => postData({url: config.getPage, data})

// 获取下单列表
const getOrderList = (data) => postData({url: config.getOrderList, data})
// 获取接单大厅列表
const takeOrderList = (data) => postData({url: config.takeOrderList, data})
// 个人技能选项
const skillOption = (data) => getData({url: config.skillOption})
// 个人选择项选中项
const selectOption = (data) => getData({url: config.selectOption + `/${data}`})
// 一键加载模板-模板列表
const getTemplateList = (data) => postData({url: config.getTemplateList,data})
// 接单类型列表
const getKindList = (data) => postData({url: config.getKindList,data})
//  更新个人信息
const updateUserInfor = (data) => postData({url: config.updateUserInfor,data})
// 保存模版
const saveTemplate = (data) => postData({url: config.saveTemplate,data})
// 我的钱包
const walletData= (data) => postData({url: config.walletData,data})
// 文件上传
const uploadFile= (data) => {
	return headImgUpload(data.file)
}
const saveUserinfo = (data) => postData({url: config.saveUserinfo,data})
// 获取验证码
const getVcode = (data) => getData({url: config.getVcode,data})
// 删除模板
const delTemplateInfor = (data,id) => postData({url: config.delTemplateInfor+`/${id}`},data)
function headImgUpload (avatarUrl){
    let tokenNow = uni.getStorageSync('token')
    return new Promise((resolve, reject) => {
        uni.uploadFile({
            url: config.uploadFile, //仅为示例，非真实的接口地址
            filePath: avatarUrl,
            name: 'file',
            header: {
              Authorization : 'bearer' + tokenNow
            },
            success (res){
                console.log('上传头像成功22222',res)
				let data = JSON.parse(res.data)
				let url =''
                if(data.status == 200){
					url = data.data.fileUrl
                    resolve(url)
                }else{
                    resolve(false)
                }
            },
            fail: () => {
                console.log('接口头像上传失败了')
                resolve(false)
              }
        })

      })
}
// 钱包详情
const walletDetails = (data) => postData({url: config.walletDetails,data})
// 充值
const rechargeWallet = (data) => postData({url: config.rechargeWallet,data})
export {
	getPage,
	getOrderList,
	takeOrderList,
	skillOption,
	selectOption,
	getTemplateList,
	getKindList,
	updateUserInfor,
	saveTemplate,
	walletData,
	uploadFile,
	saveUserinfo,
	walletDetails,
	rechargeWallet,
	getVcode,
	delTemplateInfor
}